package com.byinsight.web.actions.util;

import eg.backend.domain.User;

public class UserTokenEncoder {
	private static final String SEPARATOR = "kaixinji@gmail.com";
	
	public static String encode(User user) {
		return user.getEmail() + SEPARATOR + user.getId();
	}
	
	public static String getId(String token) {
		try {
			String id = token.substring(token.indexOf(SEPARATOR) + SEPARATOR.length());
			return id;			 
		} catch (Exception e) {
			return null;
		}
	}
	
	public static String getUsername(String token) {
		try {
			String email = token.substring(0, token.indexOf(SEPARATOR));
			return email;			 
		} catch (Exception e) {
			return null;
		}
	}
}
